package cn.ztq.test0614.service;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Color;

public class ChannelHelper {
    public final static String channelId = "my_channel_id";
    private static String channelName = "my_channel_name";
    private static int importance = NotificationManager.IMPORTANCE_DEFAULT;
    private static ChannelHelper channelHelper = new ChannelHelper();

    private ChannelHelper() {

    }

    public static ChannelHelper getInstance() {
        return channelHelper;
    }
    public static void initChannel(Context context){
        NotificationManager systemService = context.getSystemService(NotificationManager.class);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationChannel channel=new NotificationChannel(channelId,channelName,importance);
            channel.setDescription("this is my channel");
            channel.enableLights(true); // 是否启用灯光
            channel.setLightColor(Color.RED); // 设置灯光颜色
            channel.enableVibration(true); // 是否启用震动
            channel.setVibrationPattern(new long[]{100, 200, 300}); // 设置震动模式
            channel.setShowBadge(true); // 是否在图标上显示角标
            systemService.createNotificationChannel(channel);
        }
    }
}
